﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public string text1, text2;
        public Form1()
        {
            InitializeComponent();
        }
        public void file1Click(object sender, EventArgs e) {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "文本文件|*.txt";
            openFileDialog1.RestoreDirectory = true;
            openFileDialog1.FilterIndex = 1;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open);
                StreamReader sr = new StreamReader(fs, Encoding.Default);
                text1 = sr.ReadToEnd();
                textBox1.Text = text1;
                sr.Close();
            }
        }
        private void file2Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog2 = new OpenFileDialog();
            openFileDialog2.Filter = "文本文件|*.txt";
            openFileDialog2.RestoreDirectory = true;
            openFileDialog2.FilterIndex = 1;
            string filename2 = openFileDialog2.FileName;
            if (openFileDialog2.ShowDialog() == DialogResult.OK)
            {
                FileStream fs = new FileStream(openFileDialog2.FileName, FileMode.Open);
                StreamReader sr = new StreamReader(fs, Encoding.Default);
                text2 = sr.ReadToEnd();
                textBox2.Text = text2;
                sr.Close();
            }
        }
        private void combineFile(object sender, EventArgs e)
        {
            textBox2.Clear();
            text1 += text2;
            text2 = null;
            textBox1.Text = text1;
            string str = Directory.GetCurrentDirectory();
            if (!Directory.Exists(str + "\\Data"))
            {
                Directory.CreateDirectory(str + "\\Data");
            }
            FileStream fs = new FileStream(str + "\\Data\\FileCom.txt", FileMode.Create);
            StreamWriter sw = new StreamWriter(fs, Encoding.Default);
            sw.Write(text1);
            sw.Close();
            fs.Close();
        }
    }
}
